﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FacebookWrapper.ObjectModel;
using FacebookWrapper;

namespace B13_Ex01_David_300512340_Alexey_321203689
{
    public class FeedWrapper
    {
        public Post Feed { get; set; }

        public override string ToString()
        {
            return string.Format("{0}:  {1}", new UserWrapper() { UserInformation = Feed.From }, Feed.Message);
        }

        public DateTime? GetCreationTime()
        {
            return Feed.UpdateTime;
        }

        public List<FeedWrapper> SearchPostByWord(UserWrapper i_User, string i_WorldToSearch)
        {
            List<FeedWrapper> feedList = new List<FeedWrapper>();
            List<FeedWrapper> sortFeedList = new List<FeedWrapper>();

            feedList = i_User.GetFeedsList();
            foreach (Post feed in i_User.UserInformation.NewsFeed)
            {
                if (feed.Message != null && feed.Message.Contains(i_WorldToSearch))
                {
                    sortFeedList.Add(new FeedWrapper() { Feed = feed });
                }
            }

            return sortFeedList;
        }

        public List<FeedWrapper> SearchPostByDate(UserWrapper i_User, DateTime i_From, DateTime i_To)
        {
            List<FeedWrapper> feedList = new List<FeedWrapper>();
            List<FeedWrapper> sortFeedList = new List<FeedWrapper>();

            feedList = i_User.GetFeedsList();
            foreach (Post feed in i_User.UserInformation.NewsFeed)
            {
                if (feed.Message != null)
                {
                    if ((feed.CreatedTime >= i_From) && (feed.CreatedTime <= i_To))
                    {
                        sortFeedList.Add(new FeedWrapper() { Feed = feed });
                    }
                }
            }

            return sortFeedList;
        }

        public List<FeedWrapper> SearchPostByWordAndDate(UserWrapper i_User, string i_WorldToSearch, DateTime i_From, DateTime i_To)
        {
            List<FeedWrapper> feedList = new List<FeedWrapper>();
            List<FeedWrapper> sortFeedList = new List<FeedWrapper>();

            feedList = i_User.GetFeedsList();
            foreach (Post feed in i_User.UserInformation.NewsFeed)
            {
                if (feed.Message != null && feed.Message.Contains(i_WorldToSearch))
                {
                    if ((feed.CreatedTime >= i_From) && (feed.CreatedTime <= i_To))
                    {
                        sortFeedList.Add(new FeedWrapper() { Feed = feed });
                    }
                }
            }

            return sortFeedList;
        }
    }
}
